package com.shuzijun.leetcode.editor.cn;

import java.util.List;

public class WordBreak{
    public static void main(String[] args) {
         Solution solution = new WordBreak().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public boolean wordBreak(String s, List<String> wordDict) {
        int n = s.length();
        boolean[] dp = new boolean[n + 1];
        dp[0] = true;
        for (int i = 1; i <= n; i++) {
            for (String word: wordDict
                 ) {
                int len = word.length();
                int startp = i-len;
                if (startp >= 0 && s.startsWith(word,startp) && dp[i-len]){
                    dp[i] = true;
                    break;
                }
            }
        }

        return dp[n];
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}